package org.wk.concurrent.app1;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;

public class FetchList {
	private ConcurrentLinkedQueue<String> fetchList = null;
	private static final int SIZE = 5;
	
	public FetchList() {
		fetchList = new ConcurrentLinkedQueue<String>();

		List<String> urls = new ArrayList<String>();

		// 生成url list
		for (int i = 0; i < SIZE; i++) {
			String url = "http://www.yinyuetai.com/mv/all?page=" + i;
			urls.add(url);
		}

		fetchList.addAll(urls);
	}

	/**
	 * 从fetchList中取出栈顶元素
	 * 
	 * @return
	 */
	public String getUrl() {
		return fetchList.poll();
	}

	/**
	 * 返回抓取列表的大小
	 * 
	 * @return
	 */
	public int size() {
		return SIZE;
	}

	/**
	 * 清空抓取队列
	 */
	public void clear() {
		fetchList.clear();
	}

	public static void main(String[] args) {
		FetchList list = new FetchList();
		System.out.println(list.size());
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.getUrl());
		}
	}
}
